package com.chen.demo.controller;

/**
 * 区域的controller
 */
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.chen.demo.domain.Area;
import com.chen.demo.service.dao.AreaServiceDao;

@RestController
@RequestMapping("/superadmin")
public class AreaController {

	@Autowired
	private AreaServiceDao serviceDao;

	/**
	 * 1查询列表
	 * 
	 * @return
	 */
	@RequestMapping(value = "/listarea", method = RequestMethod.GET)
	private Map<String, Object> listArea() {
		Map<String, Object> map = new HashMap<String, Object>();
		List<Area> list = serviceDao.getAreaList();
		map.put("areaList", list);
		return map;
	}

	/**
	 * 2根据id查询单个区域
	 * 
	 * @return
	 */
	@RequestMapping(value = "/getareabyid", method = RequestMethod.GET)
	private Map<String, Object> getAreaById(Integer areaId) {
		Map<String, Object> map = new HashMap<String, Object>();
		Area area = serviceDao.getAreaById(areaId);
		map.put("area", area);
		return map;
	}

	/**
	 * 3添加一个区域
	 * 
	 * @return
	 */
	@RequestMapping(value = "/addarea", method = RequestMethod.POST)
	private Map<String, Object> addArea(@RequestBody Area area) {
		Map<String, Object> map = new HashMap<String, Object>();
		boolean addArea = serviceDao.addArea(area);
		map.put("success", addArea);
		return map;
	}

	/**
	 * 4更细一个区域
	 * 
	 * @return
	 */
	@RequestMapping(value = "/flusharea", method = RequestMethod.POST)
	private Map<String, Object> flushArea(@RequestBody Area area) {
		Map<String, Object> map = new HashMap<String, Object>();
		boolean addArea = serviceDao.modifyArea(area);
		map.put("success", addArea);
		return map;
	}

	/**
	 * 5删除一个区域
	 * 
	 * @return
	 */
	@RequestMapping(value = "/removearea", method = RequestMethod.GET)
	private Map<String, Object> removeArea(Integer areaId) {
		Map<String, Object> map = new HashMap<String, Object>();
		boolean addArea = serviceDao.deleteArea(areaId);
		map.put("success", addArea);
		return map;
	}
}
